package 传智播客_黑马.java高级.网络编程;

import java.io.IOException;
import java.net.*;

public class aa {
    //使用udp

    public aa() {
        try {
            InetAddress localhost = InetAddress.getByName("localhost");
            int port = 6060;
            DatagramSocket datagramSocket = new DatagramSocket();

            String str = "你好世界";
            DatagramPacket datagramPacket = new DatagramPacket(str.getBytes(),0,str.getBytes().length,localhost,port);

            datagramSocket.send(datagramPacket);

            datagramSocket.close();

        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new aa();
    }
}
